package StrBuffer;

public class StringBufferVsStringBuilder {

	public static void main(String[] args) {
		
		int looptime = 10000000;
		StringBuffer strBuffer = new StringBuffer();
		StringBuilder strBuilder = new StringBuilder();
		
		long start = System.currentTimeMillis();
		for(int i = 0; i < looptime; i++){
			
		   strBuffer.append("a");	
		}
		
		System.out.println("string buffer append :"+(System.currentTimeMillis() - start)+"ms");
		
		strBuffer = null;
	    start = System.currentTimeMillis();
		for(int i = 0; i < looptime; i++){
			
		   strBuilder.append("a");	
		}
		
		System.out.println("string builder append :"+(System.currentTimeMillis() - start)+"ms");
		strBuilder = null;
		
		System.out.println("StringBuilder is thread unsafe,StringBuffer is thread safe");
	}
	
}
